<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


if (!function_exists('array_join'))
 {
  // Joins two or more arrays together recursively; key/value pairs of the first 
   // array are replaced with key/value pairs from the subsequent arrays.  Any 
   // key/value pair not present in the first array is added to the final array 
  function array_join() 
   { 
       // Get array arguments 
       $arrays = func_get_args(); 

       // Define the original array 
       $original = array_shift($arrays); 

       // Loop through arrays 
       foreach ($arrays as $array) 
       { 
           // Loop through array key/value pairs 
           foreach ($array as $key => $value) 
           { 
               // Value is an array 
               if (is_array($value)) 
               { 
                   // Traverse the array; replace or add result to original array 
                   $original[$key] = array_join($original[$key], $array[$key]); 
               } 

               // Value is not an array 
               else 
               { 
                   // Replace or add current value to original array 
                   $original[$key] = $value; 
               } 
           } 
       } 

       // Return the joined array 
       return $original; 
   }
 }

 if(!function_exists('stage_started'))
 {
  function stage_started($stage_id)
  {
    $CI =& get_instance();
    $CI->load->model(array('stages_model', 'config_model'));
    $CI->load->helper('date');
    $stage = $CI->stages_model->get_by_id($stage_id);

    $time_offset = $CI->config_model->item('time_offset');
    $now = unix_to_human(now() - $time_offset, false, 'eu');
    $stage_start = $stage->stage_date;

    $started = $now >= $stage_start;

    if($stage->calculated && $started)
    {
      $started = 2;
    }
    return $started; //will return 0 if the stage is in the future, 1 if the stage is today, 2 if the stage has been calculated

  }
 }

 if(!function_exists('tour_started'))
 {
  function tour_started()
  {
    $CI =& get_instance();
    $CI->load->model(array('stages_model', 'config_model'));
    $CI->load->helper('date');
    $stage = $CI->stages_model->get_first();

    $time_offset = $CI->config_model->item('time_offset');
    $now = unix_to_human(now() - $time_offset, false, 'eu');
    $stage_start = $stage->stage_date;

    $started = $now >= $stage_start;

    return $started; //will return 0 if the first stage has not started, 1 if the first stage is today, or was in the past.

  }
 }

 if(!function_exists('config_item'))
 {
  function config_item($item)
  {
    $CI =& get_instance();
    $CI->load->model(array('config_model'));
    return $CI->config_model->item($item);
  }
 }

 if(!function_exists('number_of_users'))
 {
  function number_of_users()
  {
    $CI =& get_instance();
    $CI->load->model(array('users_model'));
    return $CI->users_model->get_number_of_users();
  }
 }

/* End of file directory_helper.php */
/* Location: ./system/helpers/directory_helper.php */